package com.jinmdz.app.dao.dao;

import com.jinmdz.app.dao.model.funeral.FuneralDeadItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


/**
 * 殡葬逝者Dao
 *
 * @author LiCongLu
 * @date 2020-02-06 13:50
 */
public interface FuneralDeadDao {

    /**
     * 按照业务编码获取未删除殡葬逝者信息
     *
     * @param businessCode 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-06 13:52
     */
    @Select(" select id,business_code,dead_name,dead_gender_code,dead_nation_code,dead_age_type_code,dead_age,birth_date" +
            " ,certificate_type_code,certificate_no,dead_name_unison,dead_name_abbr,death_date,death_cause,ash_handle_type_code" +
            " ,cremation_type_code,remains_state_code,country_code,province_id,city_id,county_id,town_id,village_id,province_city_county_full_name" +
            " ,household_registration_place,as_local,before_death_address,benefit_district_code,exemption_type_code,death_certificate_no" +
            " ,death_certificate_unit,funeral_certificate_unit,transport_place,as_arrived,arrived_time,negotiator_user_id,remark,version " +
            " from funeral_dead where business_code = #{businessCode} and deleted=0 limit 1 ")
    FuneralDeadItem getFuneralDeadByBusinessCode(@Param("businessCode") String businessCode);

    /**
     * 更新火化遗体类型
     *
     * @param cremationTypeCode 火化遗体类型
     * @param id                主键
     * @param businessCode      业务编码
     * @param modifiedUserId    修改用户外键
     * @return
     * @author LiCongLu
     * @date 2020-02-27 14:01
     */
    @Update(" update funeral_dead set cremation_type_code = #{cremationTypeCode},modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) where id = #{id} and business_code = #{businessCode} and deleted = 0 ")
    void updateForCremationTypeCode(@Param("cremationTypeCode") Integer cremationTypeCode, @Param("id") Integer id, @Param("businessCode") String businessCode, @Param("modifiedUserId") Integer modifiedUserId);

    /**
     * 通过证件号码与火化类型验证是否存在证件号码的重复性
     *
     * @param certificateNo     证件号码
     * @param cremationTypeCode 火化类型(遗体类型)
     * @param id                当前逝者主键
     * @return
     * @author LiCongLu
     * @date 2020-03-05 15:53
     */
    @Select(" select business_code from funeral_dead where certificate_no = #{certificateNo} and cremation_type_code = #{cremationTypeCode} and id != #{id} and deleted=0 ")
    @ResultType(String.class)
    String hasBusinessCodeForCertificateNo(@Param("certificateNo") String certificateNo, @Param("cremationTypeCode") Integer cremationTypeCode, @Param("id") Integer id);
}
